package com.gzz.orchid.common.core.tuple;

import com.gzz.orchid.common.core.exception.ValidationException;
import com.gzz.orchid.common.core.util.I18nUtil;
import lombok.Value;

import java.util.Objects;

/**
 * 数量
 *
 * @author higmd
 */
@Value
public class Quantity {
    Integer value;
    // 构造函数
    public Quantity(Integer value) {
        if (Objects.isNull(value) || value < 0) {
            throw new ValidationException(I18nUtil.ofMessage("数量必须大于等零"));
        }
        this.value = value;
    }

    /**
     * 加法
     */
    public Quantity add(Quantity quantity) {
        return new Quantity(this.value + quantity.getValue());
    }

    /**
     * 减法
     */
    public Quantity subtract(Quantity quantity) {
        return new Quantity(this.value - quantity.getValue());
    }
}
